package com.nebula.api.modules.app.conctroller;

import com.nebula.api.modules.app.service.AppUserService;
import com.nebula.commons.modules.form.PasswordForm;
import com.nebula.commons.modules.system.entity.SysUser;
import link.ahsj.core.entitys.ApiModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : syy
 * @description :用户实体类
 * @date : 2019/7/4 13:39
 */
@RestController
@RequestMapping("/users")
public class AppUserController {


    @Autowired
    private AppUserService userService;

    /**
     * 修改用户密码
     *
     * @param sysUser
     * @param form
     * @return
     */
    @PutMapping(value = "/updatePassword")
    public ResponseEntity<ApiModel> updatePwd(SysUser sysUser, PasswordForm form) {
        boolean b = userService.updatePsw(sysUser, form);
        return b ? ResponseEntity.ok(ApiModel.ok()) : ResponseEntity.ok(ApiModel.error("修改密码失败"));
    }

    @GetMapping("list")
    public ResponseEntity<ApiModel> list() {
        SysUser user = new SysUser();
        user.setNickName("李白");
        user.setPhone("12388888888");
        user.setRemark("这是我的个人简介");
        return ResponseEntity.ok(ApiModel.data(user));
    }

    /**
     * 获取用户资料
     */
    @GetMapping(value = "/info")
    public ResponseEntity<ApiModel> info() {
        Map<String, Object> map = new HashMap<>();
        map.put("image", null);
        map.put("name", "李白");
        map.put("phone", "12388888888");
        map.put("age", "18");
        map.put("age", "男");
        map.put("month_salary", "十两银子");
        map.put("year_salary", "120银子");
        map.put("remark", "是一名诗人");
        map.put("nation", "汉族");
        return ResponseEntity.ok(ApiModel.data(map));
    }

    @GetMapping("version")
    public ResponseEntity<ApiModel> versions() {

        Map<String, Object> map = new HashMap<>();
        map.put("versions", "1.0");
        map.put("infomation", "解决多处报错,版本优化");

        return ResponseEntity.ok(ApiModel.data(map));
    }


}
